package com.example.myproject.mybatis;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ShiXin
 * @date 2018/8/7 17:23
 */
@Component
public class DemoTest123 {
    TestA test = new TestA("mj",23);


    public void contextLoads() {
        test.setName("test1");
        testHHHH(test);
        System.out.println(test);
    }

    @Transactional(transactionManager = "transactionManager", rollbackFor = Exception.class)
    public void testHHHH(TestA as){
        test.setName("test2");
        System.out.println(1/0);

    }


    private static class TestA{

        public TestA(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        private String name;
        private Integer  age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "TestA{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
